﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using SingleUserMall.Common;
using SingleUserMall.Headline;
using SingleUserMall.HeadLine.Form;
using SingleUserMall.HeadLine.VO;

namespace SingleUserMall.HeadLine
{
    public class HeadLinesAppService : IHeadLinesAppService
    {
        private readonly IRepository<HeadLines, long> _headLinesRepository;
        public HeadLinesAppService(
            IRepository<HeadLines, long> headLinesRepository
    )
        {
            _headLinesRepository = headLinesRepository;
        }
        /// <summary>
        /// 查询今日头条列表
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<headlinVO>> GetAllHeadLinesAsync(HeadlineSerchForm form)
        {
            var headlines = _headLinesRepository.GetAll().Where(x => x.AreaCode == form.AreaCode).OrderByDescending(x=>x.CreationTime);
            return await headlines.ToPagedResultDtoAsync<HeadLines, headlinVO>(form, (c, vo) => { });
        }
        /// <summary>
        /// 查询文章详情信息
        /// </summary>
        /// <param name="ArticleId"></param>
        /// <returns></returns>
        public async Task<headlineDetailVO> GetArticleDetailAsync(long ArticleId)
        {
            var article =await _headLinesRepository.FirstOrDefaultAsync(x=>x.Id==ArticleId);
            return article.ToVO<HeadLines, headlineDetailVO>();
        }
    }
}
